<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "sys_home_banner".
 *
 * @property integer $id
 * @property integer $type
 * @property string $name
 * @property integer $designer_id
 * @property integer $img_small_id
 * @property integer $img_thumb_id
 * @property integer $img_url_id
 * @property integer $create_time
 * @property string $description
 * @property string $url
 * @property integer $useing
 * @property integer $order
 * @property string $action
 * @property integer $action_id
 * 
 */
class SysHomeBanner extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
	public $small_img_id;
	public $thumb_img_id;
	public $big_img_id;
	public $b_t_s_img_id;
	public $top_time_1;
	public $province_id;
	public $city_id;
    public static function tableName()
    {
        return 'sys_home_banner';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'designer_id', 'img_small_id', 'img_thumb_id', 'img_url_id', 'create_time', 'useing', 'order', 'action_id'], 'integer'],
            [['small_img_id','thumb_img_id','big_img_id','b_t_s_img_id','province_id','city_id'], 'integer'],
            [['action','area'], 'string', 'max' => 32],
            [['name'], 'string', 'max'=>128],
            [['description'], 'string', 'max' => 256],
            [['url'], 'string', 'max' => 256],
            [['top_time_1'], 'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'type' => Yii::t('app', 'Sys Home Banners Type'),
            'name' => Yii::t('app', 'Sys Home Banners Name'),
            'designer_id' =>  Yii::t('app', 'Designer ID'),
            'img_small_id' => 'Img Small ID',
            'img_thumb_id' => 'Img Thumb ID',
            'img_url_id' => 'Img Url ID',
            'create_time' =>  Yii::t('app', 'Create Time'),
            'description' =>  Yii::t('app', 'Description'),
            'url' => 'Url',
            'useing' =>  Yii::t('app', 'Useing'),
            'order' =>  Yii::t('app', 'Order'),
            'action' =>  Yii::t('app', 'Action'),
            'action_id' =>  Yii::t('app', 'Action ID'),
            'province_id' =>  Yii::t('app', 'Province'),
            'city_id' =>  Yii::t('app', 'City'),
            'area' =>  Yii::t('app', 'Sys Home Banners Area'),
            'top_time' => '置顶'
        ];
    }
    public static function more_area($new_area,$banner_id){
    	
    	//$sql = "select * from sys_banner_area where banner_id={$banner_id} AND area='{$area}'";
    	//$if_exist = Yii::$app->db->createCommand($sql)->queryAll();
    	$sql = "delete from sys_banner_area where banner_id={$banner_id}";
    	Yii::$app->db->createCommand($sql)->execute();
    	if($new_area != null){
	    	foreach ($new_area as $key => $val){
	    		var_dump($val);
    			Yii::$app->db->createCommand()->insert('sys_banner_area', $val)->execute();
	    	}
    	}
    }
}
